package tests;

import Common.Utils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;

public class LovePage extends Utils {
    public static String url = "http://127.0.0.1:8080/loveMusic.html";

    public LovePage() {
        super(url);
    }

    //检查页面是否加载成功
    public void LovePageRight() {
        //通过查看页面元素是否存在来检查页面加载成功与否
        driver.findElement(By.cssSelector("body > div.container > h3"));
    }


    //搜索喜欢的音乐
    public void QueryLoveMusic() throws InterruptedException {
        driver.findElement(By.cssSelector("#exampleInputName2")).sendKeys("小半");
        driver.findElement(By.cssSelector("#submit1")).click();
        Thread.sleep(2000);
        driver.findElement(By.cssSelector("#exampleInputName2")).clear();
        driver.findElement(By.cssSelector("#submit1")).click();
        Thread.sleep(2000);
    }

    //删除喜欢的音乐
    public void DeleteLoveMusic() {
        try {
            driver.findElement(By.cssSelector("#info > tr:nth-child(3) > td:nth-child(4) > button")).click();
            Thread.sleep(2000);
            Alert alert = driver.switchTo().alert();
            alert.accept();
        } catch (Exception e) {
            System.out.println("没有可删除的音乐DeleteLoveMusic");
        }
    }
}
